package com.xxx.car.web.admin;

import com.xxx.car.service.DemoService;
import com.xxx.common.base.enums.ApiResponseEnum;
import com.xxx.common.base.vo.APIResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * Created by youxiaojia on 2017/6/13.
 */
@RestController
@RequestMapping("/admin/car/demo")
public class AdminDemoController {
    @Autowired
    DemoService demoService;

    @RequestMapping(value = "/send",method = RequestMethod.GET)
    public APIResponse<?> send(){
        demoService.sendValidCodetToPhone("18520532749",60,120);
        return APIResponse.returnSuccess();
    }

    /**
     * 发送验证码
     *
     * @param phone
     * @return
     */
    @RequestMapping(value = "/send", method = RequestMethod.POST, produces = {
            "application/json; charset=UTF-8"})
    public APIResponse<?> demo(@RequestParam @NotNull String phone, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return APIResponse.returnFail(ApiResponseEnum.PARAMETER_INVALID);
        }
        demoService.sendValidCodetToPhone(phone,60,120);
        return APIResponse.returnSuccess();
    }
}
